2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__
27 #define __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__
30 //==============================================================================
32 A property that lets you pick a resource to use as an image, or create a
33 new one with a file selector.
35 template <class ElementType
>
36 class ImageResourceProperty
: public ChoicePropertyComponent
,
37 private ChangeListener
40 ImageResourceProperty (JucerDocument
& document_
,
41 ElementType
* const element_
,
43 const bool allowChoiceOfNoResource_
)
44 : ChoicePropertyComponent (name
),
47 allowChoiceOfNoResource (allowChoiceOfNoResource_
)
49 choices
.add ("-- create a new image resource -- ");
50 choices
.add (String::empty
);
51 if (allowChoiceOfNoResource_
)
52 choices
.add ("<< none >>");
53 choices
.addArray (document_
.getResources().getResourceNames());
55 document_
.addChangeListener (this);
58 ImageResourceProperty (ElementType
* const element_
,
60 const bool allowChoiceOfNoResource_
= false)
61 : ChoicePropertyComponent (name
),
63 document (*element_
->getDocument()),
64 allowChoiceOfNoResource (allowChoiceOfNoResource_
)
66 choices
.add ("-- create a new image resource -- ");
67 choices
.add (String::empty
);
68 if (allowChoiceOfNoResource_
)
69 choices
.add ("<< none >>");
71 choices
.addArray (document
.getResources().getResourceNames());
73 document
.addChangeListener (this);
76 ~ImageResourceProperty()
78 document
.removeChangeListener (this);
81 //==============================================================================
82 virtual void setResource (const String
& newName
) = 0;
84 virtual const String
getResource() const = 0;
86 //==============================================================================
87 void setIndex (int newIndex
)
91 String
resource (document
.getResources()
92 .browseForResource ("Select an image file to add as a resource",
93 "*.jpg;*.jpeg;*.png;*.gif;*.svg",
97 if (resource
.isNotEmpty())
98 setResource (resource
);
102 if (choices
[newIndex
] == "<< none >>" && allowChoiceOfNoResource
)
103 setResource (String::empty
);
105 setResource (choices
[newIndex
]);
111 if (getResource().isEmpty())
114 return choices
.indexOf (getResource());
117 void changeListenerCallback (ChangeBroadcaster
*)
123 ElementType
* const element
;
124 JucerDocument
& document
;
125 const bool allowChoiceOfNoResource
;
129 #endif // __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__